<?php 

namespace app\index\model;

use think\Model;


class Pipeline extends Model
{
    protected function scopeThinkphp($query)
    {
        $query->where('Pipeline_name','MOD');
    }

    public function Category()
    {
        return $this->hasMany('Category', 'pipeline_id' ,'id');
    }  

    public function Scene()
    {
        return $this->hasMany('Scene', 'pipeline_id' ,'id');
    }    

   public function Project()
    {
        return $this->belongsTo('Project', 'proj_id');
    } 
    
    public static function get_pip_cate_data($id){
        return self::where(['proj_id'=>$id])->with('Category')->with('Scene')->select();
    }

    public static function get_pip_id()
    {
        $get_id = Project::get_project_id();
        $get_pip_id=self::where(['pipeline_name'=>input('pipeline_name'),'proj_id' =>$get_id['id']])->field('id')->find() ;

        if (isset($get_pip_id['id'])){
            return [1 ,array('pipeline_id' => $get_pip_id['id'], )];
            }else{
            return [0 , "not found"];
        }  
    }

    public static function get_pipeline_id($data='')
    {
       return  self::where(['pipeline_name'=>input('pipeline_name'),'proj_id' =>$data['id']])->field('id')->find() ;
    }

    public static function get_data($data='')
    {
        return self::where($data)->select();
    }

    public static function get_count($data='')
    {
        return self::where($data)->count();
    }

    public static function add_data($data)
    {
        return self::insert($data);
    }

    public static function update_data($data)
    {
        return self::update($data);
    }

     public static function delete_data($data='')
    {
        return self::where($data)->delete();
    }
    
}




